package com.xiaoxin.xinlikesystem.controller;

import com.xiaoxin.xinlikesystem.common.BaseResponse;
import com.xiaoxin.xinlikesystem.common.ResultUtils;
import com.xiaoxin.xinlikesystem.exception.ErrorCode;
import com.xiaoxin.xinlikesystem.exception.ThrowUtils;
import com.xiaoxin.xinlikesystem.model.dto.thumb.DoThumbRequest;
import com.xiaoxin.xinlikesystem.service.ThumbService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0
 * @Author 武小新
 * @Date 2025/5/12 20:21
 * @注释
 */
@RestController
@RequestMapping("/thumb")
public class ThumbController {

    @Resource
    private ThumbService thumbService;

    /**
     * 点赞
     */
    @PostMapping("/doThumb")
    @Operation(summary = "点赞", description = "点赞")
    public BaseResponse<Boolean> doThumb(@RequestBody DoThumbRequest doThumbRequest, HttpServletRequest request) {
        // 1. 参数校验
        ThrowUtils.throwIf(doThumbRequest == null, ErrorCode.PARAMS_ERROR, "请求参数为空");

        // 2. 点赞
        Boolean success = thumbService.doThumb(doThumbRequest, request);
        return ResultUtils.success(success);
    }


    /**
     * 取消点赞
     */
    @PostMapping("/undoThumb")
    @Operation(summary = "取消点赞", description = "取消点赞")
    public BaseResponse<Boolean> undoThumb(@RequestBody DoThumbRequest doThumbRequest, HttpServletRequest request) {
        // 1. 参数校验
        ThrowUtils.throwIf(doThumbRequest == null, ErrorCode.PARAMS_ERROR, "请求参数为空");

        // 2. 取消点赞
        Boolean success = thumbService.undoThumb(doThumbRequest, request);
        return ResultUtils.success(success);
    }


}
